import Vue from 'vue'
import VueRouter from 'vue-router'
// 新增
import Category from 'Pages/Category/Category'
import Cate from 'Pages/Cate/Cate'
import GoodsList from 'Pages/GoodsList/GoodsList'
import Product from 'Pages/Product/Product'
// 新增完毕
import User from 'Pages/User'
import Login from 'Pages/login/Login'
import Home from 'Homes/Home'
import CouponDrawList from 'Homes/CouponDrawList'
import Disease from 'Homes/Disease'
import Kf from 'Homes/Kf'
import Mobile1 from 'Homes/Mobile1'
import Mobile2 from 'Homes/Mobile2'
import Mobile3 from 'Homes/Mobile3'
import Mobile4 from 'Homes/Mobile4'
import Instrument from 'Homes/Instrument'
import Mobile5 from 'Homes/slide/Mobile5'
import Mobile6 from 'Homes/slide/Mobile6'
import Mobile7 from 'Homes/slide/Mobile7'
import Mobile8 from 'Homes/slide/Mobile8'
import Mobile9 from 'Homes/slide/Mobile9'
import Mobile10 from 'Homes/slide/Mobile10'
import Mobile11 from 'Homes/slide/Mobile11'
import Mobile12 from 'Homes/slide/Mobile12'
import Mobile13 from 'Homes/content/Mobile13'
// 儿童节
import Childhood from 'Homes/Childhood'
// 艾滋病
import HIV from 'Homes/HIV'
// search
import Search from 'Pages/Category/Search'
Vue.use(VueRouter)

const routes = [{
    path: '/',
    redirect: '/home',
}, {
    path: '/home',
    component: Home,
    children: [
        
    ]
}, {
    path: '/login',
    component: Login,
    children: [
        
    ]
}, {
    path: '/category',
    component: Category
}, {
    path: '/cart',
    component: Cate
}, {
    path: '/user',
    component: User
},
// 新增
{path: '/goodsList/:code', component: GoodsList},
{path: '/product/:code', component: Product},
{path: '/search', component: Search},
// 新增完毕

{path: '/kf', component: Kf},
{path: '/coupon/couponDrawList', component: CouponDrawList},
{path: '/disease/index', component: Disease},
{path: '/activity/mobile/1', component: Mobile1},
{path: '/activity/mobile/2', component: Mobile2},
{path: '/activity/mobile/3', component: Mobile3},
{path: '/activity/mobile/4', component: Mobile4},
{path: '/instrument', component: Instrument},
{path: '/activity/mobile/5', component: Mobile5},
{path: '/activity/mobile/6', component: Mobile6},
{path: '/activity/mobile/7', component: Mobile7},
{path: '/activity/mobile/8', component: Mobile8},
{path: '/activity/mobile/9', component: Mobile9},
{path: '/activity/mobile/10', component: Mobile10},
{path: '/activity/mobile/11', component: Mobile11},
{path: '/activity/mobile/12', component: Mobile12},
{path: '/activity/mobile/13', component: Mobile13},
{path: '/activity/mobile/childhood', component: Childhood},
{path: '/activity/mobile/hiv', component: HIV},
]

const router = new VueRouter({
    routes,
    mode: 'history',
    scrollBehavior (to, from, savedPosition) {
        if (savedPosition) {
            return savedPosition
        } else {
            return { x: 0, y: 0 }
        }
    }
})

router.beforeEach( (to, from, next) => {
    console.log(to.path);
    if (to.path == '/user' && !sessionStorage.getItem('flag')) {
        next('/login');
    } else {
        next();
    }
    
})

export default router